package com.dcrzl.shcz.module.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dcrzl.shcz.common.entity.sys.SysRoleMenu;
import com.dcrzl.shcz.common.mapper.sys.SysRoleMenuMapper;
import com.dcrzl.shcz.common.service.impl.BaseServiceImpl;
import com.dcrzl.shcz.common.utils.PageInfo;
import com.dcrzl.shcz.common.utils.Result;
import com.dcrzl.shcz.common.utils.SysConstant;
import com.dcrzl.shcz.module.sys.service.SysRoleMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

@Service
@Slf4j
public class SysRoleMenuServiceImpl extends BaseServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {


    /**
     *
     * @param roleId 角色ID
     * @param status 数据状态值
     * @return
     */
    @Override
    public Result selectMenuIdByRoleId(Long roleId, Integer status) {
//        Example example = Example.builder(QuarterShopRoleMenu.class)
//                .select("menuId")
//                .where(WeekendSqls.<QuarterShopRoleMenu>custom()
//                        .andEqualTo(QuarterShopRoleMenu::getRoleId,roleId)
//                        .andEqualTo(QuarterShopRoleMenu::getStatus,status))
//                .build();
//        return ResultUtils.selectResult(baseMapper.selectByExample(example));
        return new Result<>();
    }

    /**
     *
     * @param roleId 角色ID
     * @param status 数据状态值
     * @return
     */
    @Override
    public Result selectPermsListByRoleId(Long roleId, Integer status) {
        Result Result ;
        //最高权限查询全部权限
        if (Objects.equals(roleId, SysConstant.ROOT_ID)){
//            Result = quarterShopMenuService.selectAllPermsList(SysConstant.DATA_NORMAL_STATUS);
//            List<QuarterShopMenu> quarterShopMenus = (List<QuarterShopMenu>) Result.getData();
//            List<String> permsList1 = new ArrayList<>();
//            quarterShopMenus.forEach(quarterShopMenu -> {
//                if(quarterShopMenu!=null&&quarterShopMenu.getPerms()!=null){
//                    permsList1.add(quarterShopMenu.getPerms());
//                }
//            });
//            Result.setData(permsList1);
        }else{
//            Result =  ResultUtils.selectResult(baseMapper.selectPermsListByRoleId (roleId,status));
        }
//        List<String> permsList = (List<String>) Result.getData();
//        Set<String> permsSet = new HashSet<>();
//        log.info(permsList.toString());
//        permsList.forEach(perms->{
//            String[] permss = perms.split(",");
//            permsSet.addAll(Arrays.asList(permss));
//        });
//        return Result.setData(permsSet);
        return new Result<>();
    }

    @Override
    public Result<List<SysRoleMenu>> selectList(SysRoleMenu sysRoleMenu) {
        LambdaQueryWrapper<SysRoleMenu> wrapper = new LambdaQueryWrapper<>();
        wrapper.ge(Objects.nonNull(sysRoleMenu.getRoleId()),SysRoleMenu::getRoleId,sysRoleMenu.getRoleId());
        return super.selectList(wrapper);
    }

    @Override
    public Result<SysRoleMenu> selectOne(SysRoleMenu sysRoleMenu) {
        LambdaQueryWrapper<SysRoleMenu> wrapper = new LambdaQueryWrapper<>();
        return super.selectOne(wrapper);
    }

    @Override
    public PageInfo<SysRoleMenu> selectPage(SysRoleMenu sysRoleMenu) {
        LambdaQueryWrapper<SysRoleMenu> wrapper = new LambdaQueryWrapper<>();
        return super.selectPage(sysRoleMenu, wrapper);
    }

    @Override
    public Result<Integer> removeById(Serializable id) {
        SysRoleMenu sysRoleMenu = new SysRoleMenu()
                .setId((Long)id)
                .setStatus(SysConstant.DATA_DELETE_STATUS);
        return this.updateById(sysRoleMenu);
    }
}